Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hidden_attributes method for default hidden attributes. #537

Closed
wants to merge 1 commit into from
Closed

Added hidden_attributes method for default hidden attributes. #537

wants to merge 1 commit into from

Conversation

mkraft
Copy link

@mkraft mkraft commented Apr 1, 2014

Adds the ability to define hidden_attributes that are not rendered by default. For example, say you have a UserSerializer with a home_address attribute that you don't want to remember to exclude every time you use that serializer. Just define your serializer with hidden_attributes :home_address and then add the expose: :home_address option in the places where you do want home_address displayed.

@steveklabnik
Copy link
Contributor

What is the advantage of doing this, when attributes are already a white list?

@mkraft
Copy link
Author

mkraft commented Jul 28, 2014

It avoids defining a new class to display select attributes in exceptional cases.

@bolshakov
Copy link
Contributor

We implemented same behavior in our app a bit different:

def filter(keys)
    default_keys = keys - hidden_attributes

    case
    when @only.present?
      keys & @only
    when @expose.present?
      default_keys + @expose
    else
      default_keys
    end
end

@steveklabnik
Copy link
Contributor

This is out of date, and I'm still not convinced it's worth it. Thank you!

@mkraft
Copy link
Author

mkraft commented Aug 22, 2014

You're welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants